<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            // 思路：右边变量的原型存在于左边变量的原型链上
            function instanceOf(left, right) {
                let leftValue = left.__proto__;
                let rightValue = right.prototype;
                while (true) {
                    if (leftValue === null) {
                        return false;
                    }
                    if (leftValue === rightValue) {
                        return true;
                    }
                    leftValue = leftValue.__proto__;
                }
            }

            function Foo() {}
            let foo = new Foo();
            let obj = new Object();

            let arr = [];
            console.log(instanceOf(arr, Array));
        </script>
    </body>
</html>
